package com.cn.wanxi.controller;

import com.cn.wanxi.Result.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
public class ProductController {

    @RequestMapping("/upload")
    public String add(@RequestParam("file") MultipartFile multipartFile) {
        if (multipartFile != null && !multipartFile.isEmpty()) {

            /**
             * 对文件名进行操作防止文件重名
             */

            //1，获取原始文件名
            String originalFilename = multipartFile.getOriginalFilename();
            //2,截取源文件的文件名前缀,不带后缀
            String fileNamePrefix = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            //3,加工处理文件名，原文件加上时间戳
            String newFileNamePrefix = fileNamePrefix + System.currentTimeMillis();
            //4,得到新文件名
            String newFileName = newFileNamePrefix + originalFilename.substring(originalFilename.lastIndexOf("."));


        }

        return "system/plansubmit/upload_success";
    }

}
